<%var csstpl = {%>

    <%};%>
        <%var jstpl = {%>
            <script>
                var app = new Vue({
                    el: "#content",
                    data: {
                        query: {
                            name: '',
                            phone: '',
                            pageNumber: 1,
                            pageSize: 10,
                            content: '',
                        },
                        data_result: {},
                        feedback: '',
                        activity_product:{},
                        activity_id:{}
                    },
                    created: function() {
                        this.loadPage("init");

                            // 在这试试
                        let form = layui.form;
                        form.render();
                    },
                    mounted() {
                        let form = layui.form;
                        let that = this;
                        form.on('submit(deleteSubmit)', function(data) {
                            console.log(data.field);
                            Ajax('/system/activity/freeAcquire/delete', data.field, function(res) {
                                if (res.state) {
                                    gx.alert(res.msg);
                                    that.loadPage('init');
                                    $("#feedbackModal").modal('hide');
                                } else {
                                    gx.alert(res.msg);
                                }
                            })
                        }),
                        form.on('submit(addSubmit)', function(data) {
                            // console.log(data.field);
                            data.field.activity_id = app.activity_id;
                             Ajax('/system/activity/freeAcquire/addProductWithFreeAcquire', data.field, function(d) {
                                if (d.state) {
                                    gx.alert(d.msg);
                                    that.loadPage();
                                    $("#addUpdateModal").modal('hide');
                                } else {
                                    gx.alert(d.msg);
                                }
                            })
                        })

                    },
                    methods: {
                        loadPage: function(model) { //载入模式有两种  init初始化载入 load分页载入
                            if (model == "init") {
                                this.query.pageNumber = 1;
                            }
                            Ajax("/system/activity/freeAcquire", this.query, function(d) {
                                console.log(d);
                                app.data_result = d.freeAcquirePage.list;
                                app.activity_id = d.activityId;
                                if (d.firstPage == true) {
                                    layui.laypage.render({
                                        elem: 'gexin_page' //注意，这里的 test1 是 ID，不用加 # 号
                                            ,
                                        layout: ['count', 'prev', 'page', 'next',
                                            'limit', 'skip'
                                        ],
                                        count: d.totalRow //数据总数，从服务端得到
                                            ,
                                        limit: app.query.pageSize,
                                        jump: function(obj, first) {
                                            app.query.pageNumber = obj.curr;
                                            if (app.query.pageSize != obj.limit) {
                                                app.query.pageSize = obj.limit;
                                                app.loadPage("init");
                                                return;
                                            }
                                            if (!first) {
                                                app.loadPage("load");
                                            }
                                        }
                                    });
                                }
                            })
                        },
                        deleteOverwrite: function(data) {
                            let that = this;
                            that.activity_product = data;
                            that.$nextTick(function() {
                                $("#feedbackModal").modal('show');
                            });
                        },
                        // splitImg:function(imgs){
                        //     if(imgs){
                        //         return imgs.split(",");
                        //     }else{
                        //         return "";
                        //     }
                        //
                        // }
                        addProduct:function() {
                            that = this;
                            this.$nextTick(function () {
                                // form.render();
                                $("#addModal").modal("show");
                            })
                        }
                    }
                })
            </script>
            <%};%>
                <%layout("../layout/_layout_layui.html",{title:"活动列表",jstpl:jstpl,csstpl:csstpl}){%>
                    <div class="layui-row" id="content" v-cloak>

                        <ul  id="productTree"></ul>

                        <div class="layui-col-md10">
                            <div class="layui-form-item ">

                            </div>
                        </div>
                        <div class="layui-col-md2">
                            <div class="layui-form-item">
                                <a @click="addProduct()" class="layui-btn"><i class="layui-icon">&#xe615;</i>添加商品</a>
                            </div>
                        </div>

                        <div class="layui-col-md12" style="margin-top: 20px">
                            <table class="layui-table ">
                                <thead>
                                    <tr>
                                        <th>产品id</th>
                                        <th>创建时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody v-for="d in data_result">
                                    <tr>
                                         <td>{{d.product_id}}</td>
                                         <td>{{d.create_time}}</td>
                                         <td>
<!--                                             <a @click="deleteOverwrite(d)" class="layui-btn layui-btn-sm" >删除</a>-->
                                        </td>
                                    </tr>
                                </tbody>
                                <tbody id="tbody_body" v-if="data_result.length==0">
                                    <tr>
                                        <td colspan="13" style="text-align:center;height:300px">
                                            <h1>没有数据</h1>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                            <fieldset id="gexin_page" class="layui-elem-field layui-field-title"></fieldset>
                        </div>

<!--                        <div class="modal fade" id="feedbackModal" tabindex="-1" role="dialog" aria-hidden="true">-->
<!--                            <form id="auditForm" class="layui-form form-horizontal ">-->
<!--                                <div class="modal-dialog">-->
<!--                                    <div class="modal-content">-->
<!--                                        <div class="modal-header">-->
<!--                                            <h4 class="modal-title">-->
<!--                                                确定删除?删除后无法恢复,请慎重！-->
<!--                                            </h4>-->
<!--                                        </div>-->
<!--                                             &lt;!&ndash; 弹出框开始  &ndash;&gt;-->
<!--                                                 &lt;!&ndash; 弹出框开始 type="hidden" &ndash;&gt;-->
<!--                                        <td>-->
<!--                                            <input type="hidden"    v-model="activity_product.id" name="id">-->
<!--                                        </td>-->
<!--                                         <div class="modal-footer">-->
<!--                                            <div class="layui-form-item">-->
<!--                                                <div class="layui-input-block">-->
<!--                                                    <button type="button" class="layui-btn" lay-submit lay-filter="deleteSubmit">确定</button>-->
<!--                                                    <button type="button" data-dismiss="modal" class="layui-btn layui-btn-primary">关闭</button>-->
<!--                                                </div>-->
<!--                                            </div>-->
<!--                                        </div>-->
<!--                                    </div>-->
<!--                                </div>-->
<!--                            </form>-->
<!--                        </div>-->
                        <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-hidden="true">
                            <form id="addForm" class="layui-form form-horizontal ">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h4 class="modal-title">
                                                请输入要添加商品信息
                                            </h4>
                                        </div>
                                        <!-- 弹出框开始  -->
                                        <!-- 弹出框开始 type="hidden" -->
                                        <div class="layui-form-item">
                                            <div style="padding: 20px;  ">
                                                <label class="layui-form-label">商品id</label>
                                                <div class="layui-inline">
                                                    <input class="layui-input" type="text" lay-verify="required|number" :value="data_result.product_id" 　placeholder="请输入要添加商品的id" name="product_id">


                                            </div>
                                        </div>
                                        <div class="modal-footer">
                                            <div class="layui-form-item">
                                                <div class="layui-input-block">
                                                    <button type="button" class="layui-btn" lay-submit lay-filter="addSubmit">确定</button>
                                                    <button type="button" data-dismiss="modal" class="layui-btn layui-btn-primary">关闭</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>

                    </div>
                    <%};%>

